#pragma once

#include <memory>
#include <mutex>
#include "AVFrame.h"
#include "source/input/InputSource.h"
#include "ThreadSafeQueue.h"

namespace Media{

typedef struct VideoScenesInItemConfig{
    int m_x;
    int m_y;
    int m_width;
    int m_height;
    int m_layers;
    InputSource::InputSourceId m_sourceId;
    std::string m_content;
    bool operator==(const VideoScenesInItemConfig& config) const{
        if(config.m_x == m_x && config.m_y == m_y &&
            config.m_width == m_width && config.m_height == m_height &&
            config.m_layers == m_layers){
                return true;
        }
        return false;
    }
}VideoScenesInItemConfig;

class VideoScenesInItem:public std::enable_shared_from_this<VideoScenesInItem>{
public:
    using Ptr = std::shared_ptr<VideoScenesInItem>;
    explicit VideoScenesInItem(VideoScenesInItemConfig  itemConfig);
    const VideoScenesInItemConfig& GetItemConfig();
    ~VideoScenesInItem();
    bool Start();
    bool Stop() const;

    bool GetFrame(AVFrame::Ptr& frame);
private:
    void sourceFrameCb(const AVFrame::Ptr& frame);
    
    ThreadSafeQueue<AVFrame::Ptr> m_frames;
    uint32_t m_failNum;
    VideoScenesInItemConfig m_itemConfig;
    InputSource::FrameConsumerId m_consumerId{};
    std::recursive_mutex m_mux;
};

}